<template>
  <div class="file-table">
    <Table :data="tableData" :select-column="false">
      <TableColumn
        label="附件名称"
        prop="name"
        fixed="left"
        :min-width="getColumnWidth(tableData, 'name', 100)"
      >
        <template #default="{ row }">
          <el-link :href="fileUrl + `/${row.id}`" type="primary">
            {{ row.name }}
          </el-link>
        </template>
      </TableColumn>
      <TableColumn
        label="上传单位"
        prop="unitName"
        :min-width="getColumnWidth(tableData, 'unitName', 100)"
      />
      <TableColumn
        label="上传人"
        prop="createUserName"
        :min-width="getColumnWidth(tableData, 'createUserName', 100)"
      />
      <TableColumn label="上传时间" :min-width="130">
        <template #default="{ row }">
          {{ formatDateStr(row.createTime, 'YYYY年MM月DD日') }}
        </template>
      </TableColumn>
      <TableColumn label="材料大小" :min-width="120">
        <template #default="{ row }">
          {{ formatBytes(row.fileSize) }}
        </template>
      </TableColumn>
    </Table>
  </div>
</template>

<script setup lang="ts">
import TableColumn from '@/components/table/TableColumn.vue'
import Table from '@/components/table/Table.vue'
import { computed, ref } from 'vue'
import { formatBytes, initIFileList } from '@/plugins/file'
import { formatDateStr } from '@/plugins/date'
import { getColumnWidth } from '@/plugins/util'

const fileUrl = ref('/supervision-api/fileController/fileDownload')

const model = defineModel<any[]>()

const tableData = computed(() => {
  return initIFileList(model.value)
})
</script>

<style scoped lang="scss">
.file-table {
  width: 100%;
}
</style>
